

(function (window, $) {

    $('.dateContainer').datepicker({
        format: 'yyyy-mm-dd',
        endDate: '0d',
        language: 'zh-CN',
        inputs: $('.datepicker'),
        autoclose: true
    });

    var loginTypeModel = [
        {type: "", name: '全部'},
        {type: "4", name: "密码登录"},
        // {type: "2", name: "验证码登录(暂未开放)"},
        {type: "1", name: "人脸识别"},
        {type: "3", name: "指纹登录"}
    ];

    var loginStatus = [
        {status: '', name: '全部'},
        {status: 1, name: '成功'},
        {status: 2, name: '失败'}
    ];

    var inquiryResults = [
        {status: '', name: '全部'},
        {status: 2, name: '成功'},
        {status: 0, name: '失败'}
    ];
    
    var checkAll = function () {
        var allCheckbox = $('.allCheckbox');
        var all = $('.logList .rowCheckbox');
        all.prop('checked', allCheckbox.prop('checked'));
    };

    var checkOne = function () {
        var allCheckbox = $('.allCheckbox');
        var all = $('.logList .rowCheckbox');
        var allChecked = all.filter(':checked');
        allCheckbox.prop('checked', all.length == allChecked.length);
    };

    var vm = avalon.define({
        $id: 'logLoginPage',
        loginTypeModel: loginTypeModel,
        loginStatus: loginStatus,
        searchModel: {
            account: '',
            corpName: '',
            beginTime: '',
            endTime: '',
            ip: '',
            loginResult: '',
            authType: ''
        },
        search: function () {
            var data = vm.searchModel.$model;
            if (data.loginResult === 2) {
                data.loginResult = 0;
            }
            if (data.beginTime) {
                data.beginTime = data.beginTime + ' 00:00:00';
            }
            if (data.endTime) {
                data.endTime = data.endTime + ' 23:59:59';
            }

            var url = 'log/login/page?' + $.param(data);
            menuFullUrl(url);
        },
        all: false,
        checkAll: checkAll,
        checkOne: checkOne
    });

    var operateVM = avalon.define({
        $id: 'logOperatePage',
        // loginTypeModel: loginTypeModel,
        // loginStatus: loginStatus,
        searchModel: {
            account: '',
            corpName: '',
            beginTime: '',
            endTime: '',
            operateIp: '',
            loginResult: '',
            authType: ''
        },
        search: function () {
            var data = operateVM.searchModel.$model;
            if (data.loginResult === 2) {
                data.loginResult = 0;
            }
            if (data.beginTime) {
                data.beginTime = data.beginTime + ' 00:00:00';
            }
            if (data.endTime) {
                data.endTime = data.endTime + ' 23:59:59';
            }

            var url = 'log/operate/page?' + $.param(data);
            menuFullUrl(url);
        },
        all: false,
        checkAll: checkAll,
        checkOne: checkOne
    });
    
    var inquiryVM = avalon.define({
        $id: 'logInquiryPage',
        inquiryResults:inquiryResults,
        searchModel: {
            userName:'',
            cardNum: '',
            beginTimeStr: '',
            endTimeStr: '',
            queryResult: '',
            account: '',
            curPage: 1,
            pageSize: 500,
            corpId:''
        },
        search: function () {
           
        	var data = inquiryVM.searchModel.$model;
            $.ajax({
    			type : "post",
    			url : "log/inquiry/page",
    			data : data,
    			success : function(result) {    				
    				$("#page-content-wrapper").html(result);   
    				inquiryVM.searchModel = data;
    				/*$("#corpId").find("option[value = '"+data.corpId+"']").attr("selected","selected");
    				$("#queryResult").find("option[value = '"+data.queryResult+"']").attr("selected","selected");*/
    			}
    		});
            
        },
        detail: function(id){
        	detailShow("inquiry/view",'log/inquiry:detail', id);
        }
        
    });
    
    avalon.scan($("#page-content-wrapper")[0]);


}(window, $));
/**
 * 查询所属机构
 * @returns
 */
function queryCorp(){
	$.ajax({
		type : "get", 
		async:false,
		url : "corp/getCorpId",
		data : '',
		dataType:"json",
		success : function(result) {
			$.ajax({
				type : "get",
				async:false,
				url : "corp/getCorpListByCorpId",
				data : {
					id:result
				},
				dataType:"json",
				success : function(data) {
					var json = $.parseJSON(data);
					for(var i=0;i<json.result.length;i++){
						console.log(json.result);
						$("#corpId").append("<option value="+json.result[i].id+">"+json.result[i].name+"</option>");
					}
				}
			});
		}
	});
	
}
